package net.bungaeting.client.android.request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.util.Log;


abstract public class Requestor {
	abstract public List<Response> doRequest(Request request);
	protected List<Response> createResponseList(Request request, Map<String, Object> mapResponseData){
		if (mapResponseData.get("responseList") instanceof String){
			Log.d("TEST", "responseData string [" + (String)mapResponseData.get("responseList") + "]");
		}
		@SuppressWarnings("unchecked")
		List<Map<String, Object>> responseList = (List<Map<String, Object>>)mapResponseData.get("responseList");
		
		List<Response> list = new ArrayList<Response>();
		if (responseList != null){
			for (Map<String, Object> mapResponse : responseList){
				list.add(createResponse(mapResponse));
			}
		}
		
		return list;
	}
	
	protected Response createResponse(Map<String, Object> mapResponse){
		String serviceId = (String)mapResponse.get("serviceId");
		String requestId = (String)mapResponse.get("requestId");
		@SuppressWarnings("unchecked")
		Map<String, Object> params = (Map<String, Object>)mapResponse.get("params");
		String returnCode = (String)mapResponse.get("returnCode");
		String returnMsg = (String)mapResponse.get("returnMsg");
		
		return new Response(serviceId, requestId, params, returnCode, returnMsg);
	}
}
